package com.tiny.mirror.service.product.support.strategy.lhc;

import com.google.common.collect.Lists;
import com.tiny.mirror.basic.common.code.CommonStatusCode;
import com.tiny.mirror.basic.web.exception.BusinessException;
import com.tiny.mirror.service.product.common.util.AbilityLhcPlayUtil;
import com.tiny.mirror.service.product.domain.ability.LhcParams.LhcItemParams;
import com.tiny.mirror.service.product.domain.ability.LhcParams.LhcPlayParams;
import com.tiny.mirror.service.product.enums.AbilityLhcCategoryEnum;
import com.tiny.mirror.service.product.enums.AbilityLhcStrategyEnum;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class LhcTxtzStrategy extends LhcTmapStrategy {

  @Override
  public AbilityLhcStrategyEnum strategy() {
    return AbilityLhcStrategyEnum.TXTZ;
  }

  @Override
  public LhcPlayParams build() {
    LhcPlayParams params = new LhcPlayParams();
    params.setCode("tm-txtz");
    params.setRule(
        "选1个或1个以上生肖，所选生肖与特别码所属生肖一致，即为中奖。\n例如：投注方案为鼠\n"
            + "开奖号码为：06(羊),27(狗),38(猪),24(牛),46(兔),32(蛇) + 49(鼠)，即中奖。"
    );
    params.setPlay(AbilityLhcStrategyEnum.TXTZ.getName());
    params.setCategory(AbilityLhcCategoryEnum.TM);
    params.setStrategy(AbilityLhcStrategyEnum.TXTZ);
    params.setLimit(1);
    params.setRewardPercent(BigDecimal.ZERO);
    List<LhcItemParams> itemParamsList = Lists.newArrayList();
    AbilityLhcPlayUtil.ANIMALS.stream().forEach(i -> {
      LhcItemParams itemParams = new LhcItemParams();
      itemParams.setItem(String.valueOf(i));
      if ("兔".equals(i)) {
        //todo 生肖计算
        itemParams.setOdds(new BigDecimal("9.5"));
      } else {
        itemParams.setOdds(new BigDecimal("11.6"));
      }
      itemParamsList.add(itemParams);
    });
    params.setItemList(itemParamsList);
    return params;
  }

  @Override
  public void checkItem(Integer limit, String... item) {
    if (Arrays.stream(item).anyMatch(i -> !AbilityLhcPlayUtil.ANIMALS.contains(i))) {
      throw new BusinessException(CommonStatusCode.COMMON_ERROR);
    }
  }
}
